/*
 * Copyright (c) 2005-2006 IntellSoft All Rights Reserved.
 */
package com.feyaSoft.home.base.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * This class is used to create tbest filter. This file will be auto called in
 * the web.xml when the application start.
 * 
 * @author fzhuang
 * @Date Oct 14, 2005
 */
public class FeyaSoftFilter implements Filter {

	private final static Log log = LogFactory.getLog(FeyaSoftFilter.class
			.getName());

	private FilterConfig filterConfig;

	// private AccountDao accountDAO;

	/**
	 */
	public void destroy() {}

	/**
	 * @param config
	 *            Description of the Parameter
	 */
	public void init(FilterConfig config) {
		this.filterConfig = config;
		ApplicationContext appCtxt = WebApplicationContextUtils
				.getWebApplicationContext(config.getServletContext());
		// accountDAO = (AccountDao) appCtxt.getBean("accountDAO");
	}

	/**
	 * Put an instance of ITradingSystemData in the session.
	 * 
	 * @param chain
	 * @param req
	 *            Description of the Parameter
	 * @param res
	 *            Description of the Parameter
	 * @exception ServletException
	 * @exception IOException
	 */
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {

		// Get Http Request & Response
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;

		chain.doFilter(request, response);

		// set cache now
		// Forces caches to obtain a new copy of the page from the origin server
		response.setHeader("Cache-Control", "no-cache");
		// Directs caches not to store the page under any circumstance
		response.setHeader("Cache-Control", "no-store");
		// Causes the proxy cache to see the page as "stale"
		response.setDateHeader("Expires", 0);
		// HTTP 1.0 backward compatibility
		response.setHeader("Pragma", "no-cache, must-revalidate, no-store");
	}

}
